package bookworm;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.LinkedList;

/**
 * a storage class responsible for storing a certain book history data(like time the book
 * was finished or time the book has been started). It also calculates how long does it take
 * to read a book based on this history(basically, it calculates the distance between startDate
 * and endDate).  
 *
 */
public class BookHistoryData 
{
	private String bookTitle;
	private LinkedList<String> bookAuthors;

	private String mediumCover;
	private String startDate;
	private String endDate;
	
	public String getBookTitle() {
		return bookTitle;
	}

	public void setBookTitle(String bookTitle) {
		this.bookTitle = bookTitle;
	}

	public String getMediumCover() {
		return mediumCover;
	}

	public void setMediumCover(String mediumCover) {
		this.mediumCover = mediumCover;
	}

	public String getStartDate() {
		return startDate;
	}

	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
	public LinkedList<String> getBookAuthors() {
		return bookAuthors;
	}

	public void setBookAuthors(LinkedList<String> bookAuthors) {
		this.bookAuthors = bookAuthors;
	}
	
	/**
	 * using startDate and endDate, it calculates the days used to finish a book
	 * @return it returns the necessary days to finish a book based on the history data
	 */
	public long calculateDaysToFinishABook()
	{
		try
		{
			SimpleDateFormat formatOfDates=new SimpleDateFormat("yyyy-MM-dd");
			
			long endDateConverted = formatOfDates.parse(endDate).getTime();
			long startDateConverted = formatOfDates.parse(startDate).getTime();

			long daysTookToRead = (Math.abs((endDateConverted-startDateConverted)/(1000*60*60*24)));
			
			return daysTookToRead;
		}
		catch(ParseException exc)
		{
			exc.printStackTrace();
			
			return -1;
		}
	}

}
